function isPromise(obj){
    //!!obj判断对象是否存在 为了拿到布尔值
    return !!obj && (typeof obj === 'object' || typeof obj === 'function') && (typeof obj.then === 'function');
}

export default ({dispatch,getStaet})=>(next)=>(action)=>{
    return isPromise(action.payload) ?
        action.payload.then((res) => {
            dispatch({...action, payload: res}); //payload是定死的
        }).catch(err=>{
            dispatch({...action, payload: err,error:true});
            return Promise.reject(err); //注意line:6 会返回整个，走到这里就是返回一个拒绝态的promise
        })
        : next(action);
}

/*
// let action = store.dispatch(action);
let {payload} = store.dispatch(action);
payload.then(res=>console.log(res),err=>console.log(err))
*/
